package cn.ncu.wechat.dao;

import cn.ncu.wechat.model.User;
import cn.ncu.wechat.model.dto.MemberCount;
import cn.ncu.wechat.model.dto.UserInfoDetailDTO;
import cn.ncu.wechat.model.dto.UserRegistry;
import cn.ncu.wechat.vo.OrderVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

/**
* @author
* @description 针对表【user(用户表)】的数据库操作Mapper
* @createDate 2025-01-07 14:39:44
* @Entity cn.ncu.wechat.modle.User
*/
@Mapper
public interface UserMapper extends BaseMapper<User> {
    Page<UserRegistry> getRegistry(String starTime,String endTime,Page<UserRegistry> pageInfo);
    UserInfoDetailDTO getUserInfoDetailDTO(Integer id);

    @Select("SELECT " +
            "COUNT(*) AS totalMembers, " +
            "SUM(CASE WHEN create_time >= CURDATE() THEN 1 ELSE 0 END) AS todayNewMembers, " +
            "SUM(CASE WHEN create_time >= DATE_FORMAT(NOW(), '%Y-%m-01') THEN 1 ELSE 0 END) AS monthNewMembers, " +
            "SUM(CASE WHEN last_login_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) THEN 1 ELSE 0 END) AS activeMembers " +
            "FROM user")
    MemberCount countMembers();
}




